#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int mat[6][6];
 
int sx, sy, ex, ey;
int minCost;
 
int min(int a,int b){
    return a < b ? a : b;
}
 
void fun(int a, int b, int cost, int state, int vis[6][6]) {
    if(a == ex && b == ey) {
        minCost = min(minCost, cost);
        return;
    } else {
        if(cost < minCost) {
            // 四个方向上面判断
            if(b-1 >= 0 && vis[a][b-1] == 0) {
                vis[a][b-1] = 1;
                fun(a, b-1, cost+state*mat[a][b-1], (state*mat[a][b-1])%4+1, vis);
                vis[a][b-1] = 0;
            }
            if(b+1 <= 5 && vis[a][b+1] == 0) {
                vis[a][b+1] = 1;
                fun(a, b+1, cost+state*mat[a][b+1], (state*mat[a][b+1])%4+1, vis);
                vis[a][b+1] = 0;
            }
            if(a-1 >= 0 && vis[a-1][b] == 0) {
                vis[a-1][b] = 1;
                fun(a-1, b, cost+state*mat[a-1][b], (state*mat[a-1][b])%4+1, vis);
                vis[a-1][b] = 0;
            }
            if(a+1 <= 5 && vis[a+1][b] == 0) {
                vis[a+1][b] = 1;
                fun(a+1, b, cost+state*mat[a+1][b], (state*mat[a+1][b])%4+1, vis);
                vis[a+1][b] = 0;
            }
        }
    }
}
 
int main(){
    int i, j;
    int vis[6][6]; //状态
    minCost = 0x7fffffff;
    for(i = 0; i < 6; i++) {
        for(j = 0; j < 6; j++) {
            scanf("%d", &mat[i][j]);
            vis[i][j] = 0;
        }
    }
    scanf("%d%d%d%d", &sx, &sy, &ex, &ey);
    fun(sx, sy, 0, 1, vis);
    printf("%d\n", minCost);
    return 0;
}
